# dict 字典,就是java的map
# 有数据字典
print('--------------创建---------------')
dict1 = {'name': 'Tom', 'age': 20, 'gender': '男'}
dict2 = {}
dict3 = dict()
print('--------------增加 -改-, 直接通过["name1"]---------------')
dict1['name1'] = 'Rose'
print(dict1)
dict1['id'] = 110
print(dict1)
print('---------------删除--------------')
print('--------------- del 删除--------------')
del dict1['id']
print(dict1)
print('--------------- clear 删除--------------')
# dict1.clear()
print(dict1)

print('------------查询-----------------')
# get和[]获取的区别就是[]不存在会报错,但是get不会报错
print(dict1['name'])
print(dict1['name1'])
print(dict1.get('name'))
# get还可以有默认值
# print(dict1.get(k='name2',default='111'))
print(dict1.get('name2', '111'))
print(dict1.get('name2'))
print('------------获取所有的keys-----------------')
print(dict1.keys())
print('------------获取所有的values-----------------')
print(dict1.values())
print('------------获取所有的items-----------------')
print(dict1.items())

print('------------字典的循环遍历-----------------')
print('--------------遍历keys-------------------')
for key in dict1.keys():
    print(key)
print('---------------遍历values------------------')
for value in dict1.values():
    print(value)
print('-----------------遍历元素 item----------------')
for item in dict1.items():
    print(f'item:{item}')
print('-----------------遍历键值对 key value----------------')
for key, value in dict1.items():
    print(f'key:{key}, value:{value}')
print('---------------------------------')
print('---------------------------------')
